#include "bsp_exit.h"
#include "bsp_delay.h"
#include "bsp_led.h"
#include "bsp_beep.h"
#include "bsp_epit.h"

static void epit_irq_handler(uint32_t nIRQ, void *args)
{
    static unsigned char state = 0;
    beep_switch(ON);
    if(EPIT1->SR & 1)
    {
        beep_switch(state);
        state = !state;
    }
    epit_clr_isr(EPIT1);

}

void test_main_epit()
{
    led_init();
    beep_init();
    epit_init(EPIT1, 0, 66000000/2);  // 1 分频 500ms
    epit_enable(EPIT1, EPIT1_IRQn, epit_irq_handler, NULL);
    beep_switch(ON);
    delay(500);
    beep_switch(OFF);
    while(1)
    {
        led_switch(0, ON);
        delay(500);
        led_switch(0, OFF);
        delay(500);
    }
}